<template>
  <div class="history-view">
    <el-table :data="historyList" style="width: 100%">
      <el-table-column prop="timestamp" label="时间" width="180">
        <template #default="{ row }">
          {{ formatTime(row.timestamp) }}
        </template>
      </el-table-column>
      <el-table-column prop="type" label="类型" width="100">
        <template #default="{ row }">
          <el-tag :type="getTypeColor(row.type)">{{ row.type }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="content" label="内容" />
      <el-table-column label="操作" width="150">
        <template #default="{ row }">
          <el-button-group>
            <el-button size="small" @click="restore(row)">恢复</el-button>
            <el-button size="small" type="danger" @click="remove(row)">删除</el-button>
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useClipboardStore } from '../stores/clipboard'
import { formatTime, getTypeColor } from '../utils/format'
import { CustomClipboardItem } from '../types/clipboard'

const store = useClipboardStore()
const historyList = ref<CustomClipboardItem[]>([])

onMounted(async () => {
  historyList.value = await store.getHistory()
})

const restore = (item: CustomClipboardItem) => {
  window.clipboardAPI.setClipboard(item)
}

const remove = async (item: CustomClipboardItem) => {
  await store.removeHistoryItem(item.id)
  historyList.value = historyList.value.filter(i => i.id !== item.id)
}
</script>

<style scoped>
.history-view {
  padding: 20px;
}
</style> 